// import request from 'umi-request';
import request from '@/utils/request';
import requestString from '@/utils/requestString.tsx';
import { TableListParams } from './data.d';

export async function queryBuyersPage(params: TableListParams) {
  return request(MC_PATH + '/api/buyers', {
    params
  });
}

/**
 * 新增境外贸易商
 * @param data
 * @returns {Promise<any>}
 */
export async function createBuyer(data) {
  return requestString(MC_PATH + '/api/buyer', {
    method: 'POST',
    data,
  });
}

/**
 * 修改境外贸易商
 * @param data
 * @returns {Promise<any>}
 */
export async function updateBuyer(data) {
  return requestString(MC_PATH + "/api/buyer", {
    method: 'PUT',
    data
  });
}


/**
 * 根据ID删除境外贸易商
 * @param {any} id
 * @returns {Promise<any>}
 */
export async function deleteBuyer({ id }) {
  return request(MC_PATH + '/api/buyer/' + id, {
    method: 'DELETE',
    requestType:'form',
    data: { id },
  });
}


/**
 * 根据ID获取单个境外贸易商
 * @param {any} id
 * @returns {Promise<any>}
 */
export async function getBuyer({ id }) {
  return request(MC_PATH + '/api/buyer/' + id, {
    method: 'GET',
    data: { id },
  });
}


//
// /**
//  * 分页查询境外贸易商
//  *
//  * @param cstId
//  * @param productName
//  * @param status
//  * @param productPage
//  * @returns {Promise.<Object>}
//  */
// export async function queryBuyersPage({ProviderPage }) {
//   return request(MC_PATH + '/api/buyers', {
//     method: 'GET',
//     data: {page: ProviderPage.page, size: ProviderPage.size },
//   });
// }



/**
 * 查询境外买家
 *
 * @param data
 * @returns {Promise.<void>}
 */
export async function queryBuyers({cstId,status,}) {
  return request(MC_PATH + '/api/buyers/all', {
    method: 'GET',
    data:{cstId,status}
  });
}

/**
 * 根据sprCode获取参数集合
 *
 * @param sprCode
 * @returns {Promise.<void>}
 */
export async function getBusinessParamsByCode({ sprCode }) {
  return request(BASEDATA_PATH + '/api/allBusinessParams', {
    method: 'GET',
    data: { sprCode },
  });
}

export async function updateRule(params: TableListParams) {
  return request('/api/rule', {
    method: 'POST',
    data: {
      ...params,
      method: 'update',
    },
  });
}
